﻿Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Edu.Ghi


Namespace GadgeteerApp1
    Partial Public Class Program
        Const dot = 300  ' dot
        Const dash = 900  ' dash is three times as long as a dot
        Const rest = 900 ' rest between letters is three times as long as a dot
        Const gap = 300 ' gap between sounds is as long as one dot
        Const frequency = 300 ' chosen frequency

        Dim melody As Melody = New Melody()



        Dim yPosition As Integer = 2
        Dim yIncrement As Integer = 10
        Dim xPosition As Integer = 2
        Dim xIncrement As Integer = 12
        Dim dotWidth As Integer = 2
        Dim dashWidth As Integer = 1

        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()
            Dim newWord As String = "HELLO WORLD"
            Debug.Print("Program Started")

            For count As Integer = 0 To newWord.Length() - 1
                Debug.Print(newWord(count))

                Select Case newWord(count)
                    Case "A"  ' dot dash
                        drawDot()
                        drawDash()


                    Case "B"  ' dash dot dot dot

                        drawDash()
                        drawDot()
                        drawDot()
                        drawDot()

                    Case "C"  ' dash dot dash dot
                        drawDash()
                        drawDot()
                        drawDash()
                        drawDot()
                    Case "D" '	-..
                        drawDash()

                        drawDot()
                        drawDot()

                    Case "E" '	.
                        drawDot()
                    Case "F" '	..-."
                        drawDot()
                        drawDot()
                        drawDash()

                        drawDot()

                    Case "G" '	--.		
                        drawDash()
                        drawDash()
                        drawDot()
                    Case "H" '	...."
                        drawDot()
                        drawDot()
                        drawDot()
                        drawDot()



                    Case "I" '	..	
                        drawDot()
                        drawDot()

                    Case "J" '	.---"
                        drawDot()
                        drawDash()
                        drawDash()
                        drawDash()

                    Case "K" '	-.-	
                        drawDash()
                        drawDot()
                        drawDash()

                    Case "L" '	.-.."
                        drawDot()
                        drawDash()
                        drawDot()
                        drawDot()

                    Case "M" '	--		
                        drawDash()
                        drawDash()

                    Case "N" '	-."
                        drawDash()
                        drawDot()

                    Case "O" '	---		

                        drawDash()
                        drawDash()
                        drawDash()



                    Case "P" '	.--."
                        drawDot()
                        drawDash()
                        drawDash()
                        drawDot()
                    Case "Q" '	--.-	
                        drawDash()
                        drawDash()
                        drawDot()
                        drawDash()

                    Case "R" '	.-."

                        drawDot()
                        drawDash()
                        drawDot()
                    Case "S" '	...		
                        drawDot()
                        drawDot()
                        drawDot()
                    Case "T" '	-"
                        drawDash()

                    Case "U" '	..-		
                        drawDot()
                        drawDot()
                        drawDash()

                    Case "V" '	...-"
                        drawDot()
                        drawDot()
                        drawDot()
                        drawDash()

                    Case "W" '	.--		
                        drawDot()
                        drawDash()
                        drawDash()
                    Case "X" '	-..-"
                        drawDash()
                        drawDot()
                        drawDot()
                        drawDash()

                    Case "Y" '	-.--		
                        drawDash()
                        drawDot()
                        drawDash()
                        drawDash()

                    Case "Z" '	--.."
                        drawDash()
                        drawDash()
                        drawDot()
                        drawDot()
                    Case " " ' Space is a new word (7 x wait)
                        melody.Add(0, gap * 7)

                End Select
                endOfCharacter()
            Next
            tunes.Play(melody)



        End Sub


        Private Sub drawDot()
            melody.Add(frequency, dot)
            melody.Add(0, gap)
            'draw it
            display.SimpleGraphics.DisplayEllipse(GT.Color.Red, xPosition, yPosition, dotWidth, dotWidth)
            xPosition = xPosition + xIncrement
        End Sub

        Private Sub drawDash()
            melody.Add(frequency, dash)
            melody.Add(0, gap)

            'draw it

            display.SimpleGraphics.DisplayLine(GT.Color.Red, dashWidth, xPosition, yPosition, xPosition + dashWidth, yPosition)
            xPosition = xPosition + xIncrement
        End Sub

        Private Sub endOfCharacter()
            yPosition = yPosition + yIncrement
            xPosition = 2
            melody.Add(0, rest)

        End Sub

    End Class
End Namespace